<CFIF isCommand EQ "savedata">
	<CFIF form.edtDESCRIPTION EQ "" OR form.edtDateFrom EQ "" OR form.edtDateTo EQ "">
		<CFSET sWarn="Fill up the required fields.">
	<CFELSE>
		<CFSET ISVALIDATED=TRUE>
		<CFIF (ISDEFINED("form.edtDateFrom") AND form.edtDateFrom NEQ "") AND (ISDEFINED("form.edtDateTo") AND form.edtDateTo NEQ "")>
			<CFIF form.edtDateFrom GT form.edtDateTo>
				<CFSET ISVALIDATED=FALSE>
				<CFSET sWarn="Start Date shouldn't be later than End Date">
			</CFIF>
		</CFIF>
		<CFIF ISVALIDATED>
			<CFIF ISDEFINED("FORM.BTNSAVEACTION") AND FORM.BTNSAVEACTION EQ "Replicate">
				<CFQUERY DATASOURCE="#client.global_dsn#" NAME="qryGSTAUTOGENFIELD">
					SELECT *
					FROM GSTAUTOGENFIELD
					WHERE TABLENAME = 'CINWORKSCHED' AND
						  FIELDNAME = 'WSNUMBER'
				</CFQUERY>
				<CFIF qryGSTAUTOGENFIELD.recordcount NEQ 0>
					<CFMODULE TEMPLATE="#client.common_path#cfm_autogen.cfm"
					SEEDKEY="#qryGSTAUTOGENFIELD.SEEDKEY#"
					CODELENGTH="#qryGSTAUTOGENFIELD.CODELENGTH#"
					COLUMNNAME="#qryGSTAUTOGENFIELD.FIELDNAME#"
					TABLENAME_FK="#qryGSTAUTOGENFIELD.TABLENAME#"
					DATASOURCE="#client.company_dsn#">
					<CFSET wsIDnum=AUTOGENVALUE>
				</CFIF>
				<CFQUERY NAME="insertWS" DATASOURCE="#client.company_dsn#">
					INSERT INTO CINWORKSCHED(WSCODE_FK,WSNUMBER,DESCRIPTION,PERSONNELIDNO,STARTDATE,ENDDATE,
						RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE)
					
                    VALUES('#sID#','#wsIDnum#','#form.edtDESCRIPTION#','#client.chapa#',
                    	#CreateODBCDate(form.edtDateFrom)#,#CreateODBCDate(form.edtDateTo)#,
	                    '#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',
                        #CreateODBCDate(Now())#,
		                '#TimeFormat(NOW(),"HH:mm:ss")#')
				</CFQUERY>
				<CFQUERY NAME="getOrigsub" DATASOURCE="#client.company_dsn#">
					SELECT PERSONNELIDNO FROM CINWSSUBSKEDPOOL
					WHERE WSNUMBER_FK='#FORM.hidWSNUM#'
				</CFQUERY>
				<CFIF getOrigsub.RECORDCOUNT>
					<CFLOOP QUERY="getOrigsub">
                        <CFSET sDate1=CreateODBCDate(form.edtDateFrom)>
						<CFQUERY NAME="getGUID" DATASOURCE="#client.company_dsn#">
							SELECT GUID, LASTNAME, FIRSTNAME FROM CMFPA
							WHERE PERSONNELIDNO='#getOrigsub.PERSONNELIDNO#'
						</CFQUERY>
						<CFLOOP CONDITION="sDate1 LTE form.edtDateTo">
							<CFQUERY NAME="saveEmpsFromCheckList" DATASOURCE="#client.company_dsn#">
								INSERT INTO CINWSSUBSKEDPOOL (WSNUMBER_FK,PERSONNELIDNO,REFERENCEDATE,GUID,
									RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, 
                                    TIMELASTUPDATE, FULLNAME)
								VALUES('#wsIDnum#','#getOrigsub.PERSONNELIDNO#',#sDate1#,'#getGUID.GUID#',				'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#','#getGUID.LASTNAME#, #getGUID.FIRSTNAME#')
							</CFQUERY>
                            <CFSET sDate1=CreateODBCDate(DATEADD("d",1,sDate1))> 
						</CFLOOP>
					</CFLOOP>
				</CFIF>
				<CFSET sMess="eWorkSked successfully created.<BR>Document Number was changed to #wsIDnum#.">
			<CFELSE>
				<CFQUERY NAME="isExist" DATASOURCE="#client.company_dsn#">
					SELECT * FROM CINWORKSCHED
					WHERE WSCODE_FK = '#sID#'
						AND WSNUMBER='#wsIDnum#'
				</CFQUERY>
				<CFIF isExist.RECORDCOUNT>
					<CFQUERY NAME="updateWS" DATASOURCE="#client.company_dsn#">
						UPDATE CINWORKSCHED
						SET DESCRIPTION		='#form.edtDESCRIPTION#'
						,STARTDATE	=#CreateODBCDate(form.edtDateFrom)#
						,ENDDATE	=#CreateODBCDate(form.edtDateTo)#
						,USERID			='#client.userid#'
						,DATELASTUPDATE		= #CreateODBCDate(Now())#
						,TIMELASTUPDATE		= '#TimeFormat(NOW(),"HH:mm:ss")#'
						WHERE WSCODE_FK = '#sID#'
							AND WSNUMBER='#wsIDnum#'
					</CFQUERY>
					<CFSET sMess="eWorkSked successfully updated">
				<CFELSE>
					<CFQUERY NAME="insertWS" DATASOURCE="#client.company_dsn#">
						INSERT INTO CINWORKSCHED(WSCODE_FK,WSNUMBER,DESCRIPTION,PERSONNELIDNO,STARTDATE,ENDDATE,
							RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE)
						VALUES('#sID#','#FORM.edtDOCNUMBER#','#form.edtDESCRIPTION#','#client.chapa#',#CreateODBCDate(form.edtDateFrom)#,#CreateODBCDate(form.edtDateTo)#,
							'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#')
					</CFQUERY>
					<CFSET sMess="eWorkSked successfully created">
				</CFIF>
			</CFIF>
		</CFIF>
	</CFIF>
</CFIF>
<CFIF isCommand EQ "deletefile">
	<CFQUERY NAME="deleteCINWORKSCHED" DATASOURCE="#client.company_dsn#">
		DELETE FROM CINWORKSCHED
		WHERE WSCODE_FK = '#sID#'
			AND WSNUMBER='#wsIDnum#'
	</CFQUERY>
	<CFQUERY NAME="deleteCINWSSUBSKEDPOOL" DATASOURCE="#client.company_dsn#">
		DELETE FROM CINWSSUBSKEDPOOL
		WHERE WSNUMBER_FK = '#wsIDnum#'
	</CFQUERY>
	<CFQUERY NAME="deleteCINWSMASTERPOOL" DATASOURCE="#client.company_dsn#">
		DELETE FROM CINWSMASTERPOOL
		WHERE WSNUMBER_FK = '#wsIDnum#'
	</CFQUERY>
	<CFQUERY NAME="deleteCINWSTEMPSKEDPOOL" DATASOURCE="#client.company_dsn#">
		DELETE FROM CINWSTEMPSKEDPOOL
		WHERE WSNUMBER_FK = '#wsIDnum#'
	</CFQUERY>
	<CFSET sMess="eWorkSked successfully deleted">
</CFIF>

<CFIF isCommand EQ "savetemp">
	<CFSET sWarn="">
	<CFIF form.tempSchedCode EQ "" OR  Form.tempStartDate eq "" or Form.tempEndDate eq "">
		<CFSET sWarn="Please fill in the following fields:<br>Schedule, Start Date, and End Date of the Temporary Schedule Folder">
	<CFELSE>
		<CFSET ISVALIDATED=TRUE>
		<CFIF (ISDEFINED("form.tempStartDate") AND form.tempStartDate NEQ "") AND (ISDEFINED("form.tempEndDate") AND form.tempEndDate NEQ "")>
			<CFIF form.tempStartDate GT form.tempEndDate>
				<CFSET ISVALIDATED=FALSE>
				<CFSET sWarn="TempSked Start Date shouldn't be later than End Date">
			</CFIF>
		</CFIF>
		<CFIF ISVALIDATED>
			<CFSET checkList = "#form.CHKPID#">
            <CFSET sDate1=CreateODBCDate(form.tempStartDate)>
            <CFSET sDate2=CreateODBCDate(form.tempEndDate)>
			<CFLOOP INDEX="i" LIST="#checkList#">
				<CFQUERY NAME="checkOverlap" DATASOURCE="#client.company_dsn#">
					SELECT * FROM CINWSTEMPSKEDPOOL
					WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						AND WSNUMBER_FK = '#wsIDnum#'
				</CFQUERY>
				<CFSET isOverlapped=False>
				<CFLOOP QUERY="checkOverlap">
					<CFSET dateCounter=sDate1>
					<CFLOOP CONDITION="dateCounter LTE sDate2">
						<CFIF dateCounter GTE checkOverlap.STARTDATE AND dateCounter LTE checkOverlap.ENDDATE>
							<CFIF sWarn EQ "">
								<CFSET sWarn="Invalid date. Check the date first, there is an overlapping temporary sked for the following employees:">
							</CFIF>
							<CFSET sWarn=sWarn & "<BR>#i#">
							<CFSET isOverlapped=true>
							<CFBREAK>
						</CFIF>
						<CFSET dateCounter=DateAdd("d", 1, "#dateCounter#")
>
					</CFLOOP>
					<CFIF isOverlapped>
						<CFBREAK>
					</CFIF>
				</CFLOOP>
				<CFIF NOT isOverlapped>
					<CFQUERY NAME="getGUID" DATASOURCE="#client.company_dsn#">
						SELECT GUID, LASTNAME, FIRSTNAME FROM CMFPA<!--- Badz 08212008--->
						WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
					</CFQUERY>
					<CFQUERY NAME="getmasterpool" DATASOURCE="#client.company_dsn#">
						SELECT * FROM CINWSTEMPSKEDPOOL
						WHERE STARTDATE=#sDate1#
							AND PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
							AND WSNUMBER_FK = '#wsIDnum#'
					</CFQUERY>
					<CFIF getmasterpool.RECORDCOUNT>
						<CFQUERY NAME="updatemasterpool" DATASOURCE="#client.company_dsn#">
							UPDATE CINWSTEMPSKEDPOOL
							SET WORKSKEDCODE='#form.tempSchedCode#',
								ENDDATE=#sDate2#
							WHERE STARTDATE=#sDate1#
								AND PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
								AND WSNUMBER_FK = '#wsIDnum#'
						</CFQUERY>
					<CFELSE>
						<CFQUERY NAME="insertmasterpool" DATASOURCE="#client.company_dsn#">
							INSERT INTO CINWSTEMPSKEDPOOL (WSNUMBER_FK,PERSONNELIDNO,STARTDATE,CATEGORY,WORKSKEDCODE,GUID,ENDDATE,
								RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE, FULLNAME)
							VALUES('#wsIDnum#','#ListGetAt(i, 1, "-")#',#sDate1#,'#form.lkCategory#','#form.tempSchedCode#','#getGUID.GUID#',#sDate2#,						'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#','#getGUID.LASTNAME#, #getGUID.FIRSTNAME#')
						</CFQUERY>
					</CFIF>
				</CFIF>
			</CFLOOP>
			<CFIF sWarn EQ "">
				<CFSET sMess="Temporary Sked successfully saved.">
			</CFIF>	
		</CFIF>
	</CFIF>
</CFIF>
<CFIF isCommand EQ "saveperm">
	<CFSET sActiveSched="N">
	<CFIF ISDEFINED("FORM.chkActSked")>
		<CFSET sActiveSched="Y">
	</CFIF>
	<CFSET sWarn="">
	<CFIF form.permSchedCode EQ "" OR  Form.permStartDate eq "">
		<CFSET sWarn="Please fill in the following fields:<br>Schedule and Start Date of the Permanent Schedule Folder">
	<cfelse>
		<CFSET checkList = "#form.CHKPID#">
        <CFSET sDate1=CreateODBCDate(form.permStartDate)>
		<CFLOOP INDEX="i" LIST="#checkList#">
			<CFSET isProceed=true>
			<CFIF sActiveSched EQ "Y">
				<CFQUERY NAME="getactivesked" DATASOURCE="#client.company_dsn#">
					SELECT STARTDATE FROM CINWSMASTERPOOL
					WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						AND WSNUMBER_FK = '#wsIDnum#'
						AND ACTIVESKED='Y'
				</CFQUERY>
				<CFIF getactivesked.RECORDCOUNT EQ 1 AND getactivesked.STARTDATE EQ sDate1>
					<CFSET isProceed=true>
				<CFELSEIF getactivesked.RECORDCOUNT GT 0>
					<CFSET sWarn=listappend(sWarn,"#i#<br>", " ")>
					<CFSET isProceed=false>
				</CFIF>
			</CFIF>
			<CFIF isProceed>
				<CFQUERY NAME="getGUID" DATASOURCE="#client.company_dsn#">
					SELECT GUID, LASTNAME, FIRSTNAME FROM CMFPA<!--- Badz 08212008--->
					WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
				</CFQUERY>
				<CFQUERY NAME="getmasterpool" DATASOURCE="#client.company_dsn#">
					SELECT * FROM CINWSMASTERPOOL
					WHERE STARTDATE=#sDate1#
						AND PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						AND WSNUMBER_FK = '#wsIDnum#'
				</CFQUERY>
				<CFIF getmasterpool.RECORDCOUNT>
					<CFQUERY NAME="updatemasterpool" DATASOURCE="#client.company_dsn#">
						UPDATE CINWSMASTERPOOL
						SET WORKSKEDCODE='#form.permSchedCode#',
							ACTIVESKED='#sActiveSched#'
						WHERE WSNUMBER_FK = '#wsIDnum#'
							AND PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
							AND STARTDATE=#sDate1#
					</CFQUERY>
				<CFELSE>
					<CFQUERY NAME="insertmasterpool" DATASOURCE="#client.company_dsn#">
						INSERT INTO CINWSMASTERPOOL (WSNUMBER_FK,PERSONNELIDNO,ACTIVESKED,CATEGORY,WORKSKEDCODE,GUID,STARTDATE,
							RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE, FULLNAME)
						VALUES('#wsIDnum#','#ListGetAt(i, 1, "-")#','#sActiveSched#','#form.lkCategory#','#form.PERMSCHEDCODE#','#getGUID.GUID#',#sDate1#,					'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#','#getGUID.LASTNAME#, #getGUID.FIRSTNAME#')
					</CFQUERY>
				</CFIF>
				<CFSET sMess="Permanent Sked successfully saved.">
			</CFIF>
		</CFLOOP>
		<CFIF sWarn NEQ "">
			<CFSET sMess="Only one Active Sched is allowed for employees:<br><br>" & sWarning>
		</CFIF>
	</CFIF>
</CFIF>
<CFIF isCommand EQ "delsub">
	<CFIF isDefined("form.CHKPID") and isDefined("form.CHKMASTER")>
		<CFSET checkList = "#form.CHKPID#">
		<CFLOOP INDEX="dDate" LIST="#form.CHKMASTER#">
			<CFLOOP INDEX="i" LIST="#checkList#">
				<CFQUERY NAME="delMaster" DATASOURCE="#client.company_dsn#">
					DELETE FROM CINWSSUBSKEDPOOL
					WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						AND referencedate='#dDate#'
						<!---AND ENDDATE='#LISTGETAT(dDate,2,"~")#'--->
						AND WSNUMBER_FK = '#wsIDnum#'
				</CFQUERY>
			</CFLOOP>
		</CFLOOP>
		<CFSET sMess="SubTemporary Sked successfully removed.">
	</CFIF>
</CFIF>
<CFIF isCommand EQ "deltemp">
	<CFIF isDefined("form.CHKPID") and isDefined("form.CHKMASTER")>
		<CFSET checkList = "#form.CHKPID#">
		<CFLOOP INDEX="dDate" LIST="#form.CHKMASTER#">
			<CFLOOP INDEX="i" LIST="#checkList#">
				<CFQUERY NAME="delMaster" DATASOURCE="#client.company_dsn#">
					DELETE FROM CINWSTEMPSKEDPOOL
					WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						AND STARTDATE='#LISTGETAT(dDate,1,"~")#'
						<!---AND ENDDATE='#LISTGETAT(dDate,2,"~")#'--->
						AND WSNUMBER_FK = '#wsIDnum#'
				</CFQUERY>
			</CFLOOP>
		</CFLOOP>
		<CFSET sMess="Temporary Sked successfully removed.">
	</CFIF>
</CFIF>
<CFIF isCommand EQ "delperm">
	<CFIF isDefined("form.CHKPID") and isDefined("form.CHKMASTER")>
		<CFSET checkList = "#form.CHKPID#">
		<CFLOOP INDEX="dDate" LIST="#form.CHKMASTER#">
			<CFLOOP INDEX="i" LIST="#checkList#">
				<CFQUERY NAME="delMaster" DATASOURCE="#client.company_dsn#">
					DELETE FROM CINWSMASTERPOOL
					WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						AND STARTDATE='#dDate#'
						AND WSNUMBER_FK = '#wsIDnum#'
				</CFQUERY>
			</CFLOOP>
		</CFLOOP>
		<CFSET sMess="Permanent Sked successfully removed.">
	</CFIF>
</CFIF>
<CFIF isCommand EQ "updatechanges" OR isCommand EQ "resetrecord">
	<CFSET ISVALIDATED=TRUE>
	<CFIF (ISDEFINED("form.edtDateFrom") AND form.edtDateFrom NEQ "") AND (ISDEFINED("form.edtDateTo") AND form.edtDateTo NEQ "")>
		<CFIF form.edtDateFrom GT form.edtDateTo>
			<CFSET ISVALIDATED=FALSE>
			<CFSET sWarn="Start Date shouldn't be later than End Date">
		</CFIF>
	</CFIF>
	<CFIF ISVALIDATED>
		<CFQUERY NAME="updateWS" DATASOURCE="#client.company_dsn#">
			UPDATE CINWORKSCHED
			SET
			<CFIF ISDEFINED("form.edtDateFrom") AND form.edtDateFrom NEQ "">
				STARTDATE	=#CreateODBCDate(form.edtDateFrom)#, 
			</CFIF>
			<CFIF ISDEFINED("form.edtDateTo") AND form.edtDateTo NEQ "">
				ENDDATE		=#CreateODBCDate(form.edtDateTo)#,
			</CFIF>
			USERID			='#client.userid#',
			DATELASTUPDATE	= #CreateODBCDate(Now())#,
			TIMELASTUPDATE		= '#TimeFormat(NOW(),"HH:mm:ss")#'
			WHERE WSCODE_FK = '#sID#'
				AND WSNUMBER='#wsIDnum#'
		</CFQUERY>
		<CFIF isDefined("form.CHKPID")>
			<CFSET checkList = "#form.CHKPID#">
			<CFLOOP INDEX="i" LIST="#checkList#">
				<CFIF isCommand NEQ "resetrecord">
					<CFLOOP index="rowcount" from="1" to="#form.fldRowCount#">
						<CFQUERY NAME="checkLKSubTemp" DATASOURCE="#client.company_dsn#">
							SELECT PATTERNCODE
							FROM CLKWSPATTERN
							WHERE PATTERNCODE='#evaluate("form.edtSchedCode" & rowcount)#'
						</CFQUERY>
						<CFIF checkLKSubTemp.RECORDCOUNT>
							<CFQUERY NAME="QRYdeletesub" DATASOURCE="#client.company_dsn#">
								DELETE FROM CINWSSUBSKEDPOOL
								WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
									AND WSNUMBER_FK = '#wsIDnum#'
									AND REFERENCEDATE='#evaluate("form.fldRefDate" & rowcount)#'
							</CFQUERY>
							<CFQUERY NAME="getGUID" DATASOURCE="#client.company_dsn#">
								SELECT GUID, LASTNAME, FIRSTNAME FROM CMFPA
								WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
							</CFQUERY>
							<CFQUERY NAME="saveEmpsFromCheckList" DATASOURCE="#client.company_dsn#">
								INSERT INTO CINWSSUBSKEDPOOL (WSNUMBER_FK,PERSONNELIDNO,REFERENCEDATE,GUID,PATTERNCODE,CATEGORY,
									RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE, FULLNAME)
								VALUES('#wsIDnum#','#ListGetAt(i, 1, "-")#',#CreateODBCDate(evaluate("form.fldRefDate" & rowcount))#,'#getGUID.GUID#','#evaluate("form.edtSchedCode" & rowcount)#','#evaluate("form.PATTERNCODELKCATEGORY" & rowcount)#',
									'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#','#getGUID.LASTNAME#, #getGUID.FIRSTNAME#')
							</CFQUERY>
						</CFIF>
					</CFLOOP>
					<CFSET sMess="SubTemporary Sked successfully saved.">
				</CFIF>
				<CFIF isCommand EQ "resetrecord">
					<CFLOOP index="rowcount" from="1" to="#form.fldRowCount#">
						<CFQUERY NAME="saveEmpsFromCheckList" DATASOURCE="#client.company_dsn#">
							UPDATE CINWSSUBSKEDPOOL 
							SET PATTERNCODE=NULL
							WHERE WSNUMBER_FK = '#wsIDnum#'
								AND PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
								AND REFERENCEDATE='#evaluate("form.fldRefDate" & rowcount)#'
						</CFQUERY>
					</CFLOOP>
					<CFSET sMess="SubTemporary Sked successfully restored.">
				</CFIF>
			</CFLOOP>
		</CFIF>
	</CFIF>
</CFIF>
<CFIF isCommand EQ "deleteemp">
	<CFIF isdefined("FORM.chkPID")>
		<CFSET sList="">
		<CFLOOP LIST="#FORM.chkPID#" INDEX="lPID">
			<CFSET sList=listappend(sList,"'" & ListGetAt(lPID, 1, "-") & "'")>
		</CFLOOP>
		<CFQUERY NAME="QRYdeletesub" DATASOURCE="#client.company_dsn#">
			DELETE FROM CINWSSUBSKEDPOOL
			WHERE PERSONNELIDNO in (#preservesinglequotes(sList)#)
				AND WSNUMBER_FK='#wsIDnum#'
		</CFQUERY>
		<CFQUERY NAME="deleteCINWSMASTERPOOL" DATASOURCE="#client.company_dsn#">
			DELETE FROM CINWSMASTERPOOL
			WHERE PERSONNELIDNO in (#preservesinglequotes(sList)#)
				AND WSNUMBER_FK='#wsIDnum#'
		</CFQUERY>
		<CFQUERY NAME="deleteCINWSTEMPSKEDPOOL" DATASOURCE="#client.company_dsn#">
			DELETE FROM CINWSTEMPSKEDPOOL
			WHERE PERSONNELIDNO in (#preservesinglequotes(sList)#)
				AND WSNUMBER_FK='#wsIDnum#'
		</CFQUERY>
		<CFSET sMess="Employee/s successfully removed.">
	</CFIF>
</CFIF>
<CFIF isCommand EQ "AddEmp">
	<CFSET checkList = "">
	<CFIF isDefined("form.hidCheck") AND isDefined("form.btnAddEmp")>
		<CFSET checkList = "#form.hidCheckList#">
		<CFLOOP INDEX="i" LIST="#form.hidUnCheck#">
			<CFIF listFind(checkList,i) NEQ 0>
				<CFSET checkList = listDeleteAt(checkList,listFind(checkList,i))>
			</CFIF>
		</CFLOOP>

		<CFLOOP INDEX="i" LIST="#form.hidCheck#">
			<CFIF listFind(checkList,i) EQ 0>
				<CFSET checkList = listAppend(checkList,i)>
			</CFIF>
		</CFLOOP>
		<CFQUERY NAME="getEmpList" DATASOURCE="#client.company_dsn#">
			SELECT DISTINCT PERSONNELIDNO FROM CINWSSUBSKEDPOOL
			WHERE WSNUMBER_FK = '#wsIDnum#'
		</CFQUERY>

		<CFLOOP QUERY="getEmpList">
			<CFIF listFind(checkList,getEmpList.PERSONNELIDNO) NEQ 0>
				<CFSET checkList = listDeleteAt(checkList,listFind(checkList,getEmpList.PERSONNELIDNO))>
			</CFIF>
		</CFLOOP>
		<CFQUERY NAME="getWS" DATASOURCE="#client.company_dsn#">
			SELECT * FROM CINWORKSCHED
			WHERE WSNUMBER='#wsIDnum#'
		</CFQUERY>
		<CFLOOP INDEX="i" LIST="#checkList#">
            <CFSET sDate1=CreateODBCDate(getWS.STARTDATE)>
			<CFQUERY NAME="getGUID" DATASOURCE="#client.company_dsn#">
				SELECT GUID, LASTNAME, FIRSTNAME FROM CMFPA
				WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
			</CFQUERY>
			<CFLOOP CONDITION="sDate1 LTE getWS.endDATE">
				<CFQUERY NAME="saveEmpsFromCheckList" DATASOURCE="#client.company_dsn#">
					INSERT INTO CINWSSUBSKEDPOOL (WSNUMBER_FK,PERSONNELIDNO,REFERENCEDATE,GUID,
						RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE, FULLNAME)
					VALUES('#wsIDnum#','#i#',#sDate1#,'#getGUID.GUID#',						'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#','#getGUID.LASTNAME#,#getGUID.FIRSTNAME#')
				</CFQUERY>
                <CFSET sDate1=CreateODBCDate(DATEADD("d",1,sDate1))>
			</CFLOOP>
		</CFLOOP>
		<CFIF checkList EQ "">
			<CFSET sMess="No employee was selected.">
		<CFELSE>
			<CFSET sMess="Employee/s successfully added.">
		</CFIF>
	</CFIF>
</CFIF>

<CFIF isCommand EQ "savesub">
	<CFQUERY NAME="isExist" DATASOURCE="#client.company_dsn#">
		SELECT STARTDATE,ENDDATE FROM CINWORKSCHED
		WHERE WSCODE_FK = '#sID#'
			AND WSNUMBER='#wsIDnum#'
	</CFQUERY>
	<CFIF isDefined("form.CHKPID") AND ISDEFINED("FORM.subStartDate") AND ISDEFINED("FORM.subENDDATE") AND FORM.subENDDATE NEQ "" AND FORM.subStartDate NEQ "" AND (ISDEFINED("form.subSchedCode")  AND FORM.subSchedCode NEQ "")>    
		<CFSET checkList = "#form.CHKPID#">
		<CFSET sdatefrom=CreateODBCDate(FORM.subStartDate)>
		<CFSET sdateto=CreateODBCDate(FORM.subENDDATE)>
		<CFSET ISVALIDATED=TRUE>
		<CFIF (ISDEFINED("form.subStartDate") AND form.subStartDate NEQ "") AND (ISDEFINED("form.subENDDATE") AND form.subENDDATE NEQ "")>
			<CFIF form.subStartDate GT form.subENDDATE>
				<CFSET ISVALIDATED=FALSE>
				<CFSET sWarn="SubTempSked Start Date shouldn't be later than End Date">
			</CFIF>
		</CFIF>
		<CFIF ISVALIDATED>
			<CFSET sdateStart=sdatefrom>
			<CFLOOP INDEX="i" LIST="#checkList#">
				<CFSET sdatefrom=sdateStart>
				<CFLOOP CONDITION="sdatefrom LTE sdateto">
					<CFIF sdatefrom GTE CreateODBCDate(isExist.STARTDATE) AND sdatefrom LTE CreateODBCDate(isExist.ENDDATE)>
						<CFQUERY NAME="DeleteEmp" DATASOURCE="#client.company_dsn#">
							DELETE FROM CINWSSUBSKEDPOOL
							WHERE WSNUMBER_FK = '#wsIDnum#'
								AND PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
								AND REFERENCEDATE=#sdatefrom#
						</CFQUERY>
						<CFQUERY NAME="getGUID" DATASOURCE="#client.company_dsn#">
							SELECT GUID, LASTNAME, FIRSTNAME FROM CMFPA
							WHERE PERSONNELIDNO='#ListGetAt(i, 1, "-")#'
						</CFQUERY>
						<CFQUERY NAME="saveEmpsFromCheckList" DATASOURCE="#client.company_dsn#">
							INSERT INTO CINWSSUBSKEDPOOL (WSNUMBER_FK,PERSONNELIDNO,REFERENCEDATE,GUID,CATEGORY,PATTERNCODE,
								RECCREATEDBY, RECDATECREATED, USERID, DATELASTUPDATE, TIMELASTUPDATE, FULLNAME)
							VALUES('#wsIDnum#','#ListGetAt(i, 1, "-")#',#sdatefrom#,'#getGUID.GUID#','#FORM.lkCategory#','#FORM.subSchedCode#',							'#client.userid#',#CreateODBCDate(Now())#,'#client.userid#',#CreateODBCDate(Now())#,'#TimeFormat(NOW(),"HH:mm:ss")#','#getGUID.LASTNAME#, #getGUID.FIRSTNAME#')
						</CFQUERY>
					</CFIF>
					<CFSET sdatefrom=dateformat(DATEADD("d",1,sdatefrom),"mm/dd/yyyy")>
                    <CFSET sdatefrom = CreateODBCDate(sdatefrom)>
				</CFLOOP>  
			</CFLOOP>
			<CFSET sMess="SubTemporary Sked successfully saved.">
		</CFIF>
	<CFELSE>
		<CFSET sWarn="Please fill in the following fields:<br>Schedule, Start Date, and End Date of the Sub-Temporary Schedule Folder">
	</CFIF>
</CFIF>